package com.kk.controller;

import com.kk.model.Menu;
import com.kk.model.User;
import com.kk.repository.MenuRepository;
import com.kk.repository.UserRrepository;
import com.kk.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * @function:
 * @author: kevin
 * @date: 2018-10-13 14:20
 */
@Controller
public class BeetlController {

    @Autowired
    private MenuService menuService;

    @Autowired
    private UserRrepository userRrepository;

    @GetMapping({"/", "/index", "beetl"})
    public String beetl(Model model) {
//        model.addAttribute("beetl", "测试beetl模板引擎");
        User user = userRrepository.findByAccount("admin");
        List<Menu> titles = menuService.getMenuTreeByUser(user);
        model.addAttribute("titles", titles);
        model.addAttribute("user", user);
        return "index";
    }

    @GetMapping("/test")
    public String test(Model model) {
        return "test";
    }

    @GetMapping("/login")
    public String login(Model model) {
        return "login";
    }
}
